// pages/activityContent/activityContent.js
const {
    getActivityContent
} = require('../../services/activityContentReq')
Page({

    /**
     * 页面的初始数据
     */
    data: {
        list: [],
        pageNum: 1,
        pageSize: 10,
        isFinish: false
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.handleGetAllActivity()
    },


    onReachBottom: function () {
        console.log('刷新')
        this.handleGetAllActivity()
    },

    // 获取全部活动风采
    handleGetAllActivity() {
        if (this.data.isFinish) {
            return
        }
        wx.showLoading({
            title: '加载中',
        })

        getActivityContent(this.data.pageNum, this.data.pageSize, res => {
            console.log(res)


            let list = res.data.data.list
            if (list.length < this.data.pageSize) {
                this.setData({
                    isFinish: true
                })
            }
            wx.hideLoading()

            this.setData({
                list: this.data.list.concat(list),
                pageNum: this.data.pageNum + 1
            })
        })
    },

    // 跳转风采详情
    handleGoDetail(e) {
        const id = e.currentTarget.dataset.id
        wx.navigateTo({
            url: '../contentDetail/contentDetail?id=' + id,
        })
    }
})
